package com.geek.javase.ch14.work.threadlambda;

public class ThreadDemo {
    public static void main(String[] args) {
        /* 多线程的第一种启动方式：
        1.自己定义一个类继承Thread
        2.重写run方法
        3.创建子类的对象，并启动线程*/

        /*MyThread myThread = new MyThread();
        myThread.setName("线程1");
        myThread.start();
        MyThread myThread1 = new MyThread();
        myThread1.run();*/

        //使用lambda表达式创建线程
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                Thread.currentThread().setName("线程1");
                System.out.println(Thread.currentThread().getName() + " " + i);
            }
        });
        thread.start();
    }
}

/*class MyThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+" " + i);
        }
    }
} */
